package com.wn.quality.web;

import com.wn.common.PageBean;
import com.wn.common.ResponseEntity;
import com.wn.entity.IncomingInspection;
import com.wn.entity.InventoryBookkeeping;
import com.wn.quality.mapper.InventoryBookkeepingMapper;
import com.wn.quality.service.IncomingInspectionService;
import com.wn.quality.vo.IncomingInspectionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wuqingting
 * @date 2022/10/24
 */
@RestController
@RequestMapping("/quality/incomingIns")
public class IncomingInspectionController {
    @Autowired
    private IncomingInspectionService incomingInspectionService;
    @Autowired
    private InventoryBookkeepingMapper inventoryBookkeepingMapper;

    @RequestMapping("/add")
    public ResponseEntity add(@RequestBody IncomingInspection incomingInspection){
        incomingInspectionService.add(incomingInspection);

        return ResponseEntity.success;
    }

    @RequestMapping("/update")
    public ResponseEntity update(@RequestBody IncomingInspection incomingInspection){
        incomingInspectionService.complete(incomingInspection);

        return ResponseEntity.success;
    }

    @RequestMapping("/getPage")
    public ResponseEntity getPage(@RequestBody IncomingInspectionVo incomingInspectionVo){
        PageBean<IncomingInspection> pageBean = incomingInspectionService.getPageByCondition
                (incomingInspectionVo.getIncomingInspection(), incomingInspectionVo.getCurrPage(), incomingInspectionVo.getPageSize());

        return new ResponseEntity(pageBean);
    }

    @RequestMapping("/getInventoryByPage")
    public ResponseEntity getInventoryByPage(@RequestBody IncomingInspectionVo incomingInspectionVo){
        PageBean<InventoryBookkeeping> pageBean = incomingInspectionService.getInventoryByPage(incomingInspectionVo.getIncomingInspection().getInventoryBookkeeping().getState()
            ,incomingInspectionVo.getCurrPage(), incomingInspectionVo.getPageSize());

        return new ResponseEntity(pageBean);
    }
}
